//
//  NetAPIManager.m
//  Coding_My
//
//  Created by showXxie on 2017/8/21.
//  Copyright © 2017年 sooxie. All rights reserved.
//

#import "NetAPIManager.h"
#import "NetworkingTools.h"

@implementation NetAPIManager

+ (instancetype)manager {
    static NetAPIManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[NetAPIManager alloc]init];
    });
    return manager;
}

#pragma mark - 登录
- (void)loginPath:(NSString *)path Params:(id)params andBlock:(void (^)(id, NSError *))block {
    
    [[NetworkingTools share] requestMethod:Post path:path withParams:params andBlock:^(id data, NSError *error) {
        
        id resultData = [data valueForKeyPath:@"data"];
        
        if (resultData) {
            
            [[NetworkingTools share] requestMethod:Get path:@"api/user/unread-count" withParams:nil andBlock:^(id data, NSError *error_check) {
                //检查当前账号未设置邮箱和GK

                if (error_check.userInfo[@"msg"][@"user_need_activate"]) {
                    block(nil, error_check);
                }else{
                    
                    block(resultData,nil);
                    
                }
                
            }];

        }

        
    }];
    
}


#pragma mark - 消息
- (void)request_UnReadNotificationsWithBlock:(void (^)(id data, NSError *error))block {
    
    [[NetworkingTools share] requestMethod:Get path:@"https://coding.net/api/notification/unread-count?type=0" withParams:nil andBlock:^(id data, NSError *error) {
        
        NSLog(@"%@",data);
        
    }];
    
}


- (void)request_PrivateMessages:(PrivateMessages *)priMsgs andBlock:(void (^)(id data, NSError *error))block{

    //正在加载
    priMsgs.isLoading = YES;
    
    [[NetworkingTools share] requestMethod:Get path:[priMsgs toPath] withParams:[priMsgs toParams] andBlock:^(id data, NSError *error) {
       
        priMsgs.isLoading = NO;
        
        if (data) {
            
            block(data,nil);
            
        }
 
//        NSLog(@"%@",data);
        
    }];

    
}


#pragma mark - 聊天消息列表
- (void)request_PrivateMessages2:(PrivateMessages *)priMsgs andBlock:(void (^)(id data, NSError *error))block {
    
    priMsgs.isLoading = YES;

    
    
}


@end
